*加载数据GPA1，请修改文件路径
use "E:\同步空间\EDUCATION\Economics\Econometrics\Introductory Econometrics A Modern Approach_Wooldrige\stata伍德里奇\GPA1.DTA" , clear
/*
多元回归方程：
colGPA=c+Beta1*hsGPA+Beta2*ACT+sigma   (1)
*/
sum colGPA hsGPA ACT                      //查看统计性质
reg colGPA hsGPA ACT                      //对（1）回归
/* 多元回归结果
      Source |       SS           df       MS      Number of obs   =       141
-------------+----------------------------------   F(2, 138)       =     14.78
       Model |  3.42365506         2  1.71182753   Prob > F        =    0.0000
    Residual |  15.9824444       138  .115814814   R-squared       =    0.1764
-------------+----------------------------------   Adj R-squared   =    0.1645
       Total |  19.4060994       140  .138614996   Root MSE        =    .34032

------------------------------------------------------------------------------
      colGPA |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------   --------------
       hsGPA |   .4534559   .0958129     4.73   0.000     .2640047    .6429071   | ---->Beta1 |
         ACT |    .009426   .0107772     0.87   0.383    -.0118838    .0307358   | ---->Beta2 | 
       _cons |   1.286328   .3408221     3.77   0.000      .612419    1.960237   --------------
------------------------------------------------------------------------------
*/

/*
------------------------FWL定理------------------------------------------
1、Beta1=cov(u1,y)/D(u1)=cov(u1,u2)/D(u1)=0.4534558
   hsGPA=c+系数*ACT+u1                (2)
   colGPA=c+系数ACT+u2                (3)
   ---->
   colGPA=c+Beta1*u1+u'                   ,求cov(u1,y)/D(u1)
   u2=c+Beta1*u1+u''                      ,求cov(u1,u2)/D(u1)
   
2、Beta1=Beta_1-Beta2*Alpha=0.4824346-0.009426*3.074331=0.45345596
   colGPA=c+Beta_1*hsGPA+u3           (4) ,Beta_1为colGPA对hsGPA的一元回归系数

   Alpha=cov(ACT,hsGPA)/D(hsGPA)      (5) ,Alpha为ACT对hsGPA的一元回归系数
   ACT=c+Alpha*hsGPA+u3               (6)
-------------------------------------------------------------------------
*/

*验证FWL定理1, 《计量经济学现代观点》第六版公式3.22
reg hsGPA ACT                              //对（2）回归
gen u1=hsGPA-(2.462537+0.0388968*ACT)      //求（2）残差
reg colGPA u1                              //求一元回归y=c+a*u1+残差,a=Beta1=cov(u1,y)/D(u1)=0.4534558

reg colGPA ACT                             //对（3）回归
gen u2=colGPA-(2.402979+0.027064*ACT)      //求（3）残差
reg u2 u1                                  //求一元回归u2=c+b*u1+残差,b=a=Beta1=cov(u1,y)/D(u1)=0.4534558

*验证FWL定理2, 《计量经济学现代观点》第六版公式3.23
reg colGPA hsGPA                           //对（4）回归，求Beta_1=cov(colGPA,hsGPA)/D(hsGPA)=0.4824346
reg ACT hsGPA                              //对（6）回归，求Alpha=cov(ACT,hsGPA)/D(hsGPA)=3.074331
di 0.4824346-0.009426*3.074331             //=0.4534558

